//
//  TFOnPodiumButton.swift
//  TalkfunSDKDemo
//
//  Created by 莫瑞权 on 2022/5/6.
//  Copyright © 2022 Talkfun. All rights reserved.
//

import UIKit

class TFOnPodiumButton: UIButton {
    @objc public let nameLab = UILabel()
    @objc public let imgView = UIImageView()
    @objc public let view = UIView()
    @objc public var podium:TalkfunApplyStatus = .noApply

    override init(frame: CGRect) {
        super.init(frame: frame)
    
        self.imgView.isUserInteractionEnabled = false
        self.addSubview(self.imgView)
        
        self.view.isUserInteractionEnabled = false
        self.addSubview(self.view)
      
        self.nameLab.textColor = UIColor.white
        self.nameLab.font = UIFont.PingFang(size: 11)
        self.nameLab.textAlignment = .center
        self.nameLab.isUserInteractionEnabled = false
        self.nameLab.sizeToFit();
        self.addSubview(self.nameLab)
    }
    override func layoutSubviews() {
        super.layoutSubviews()
        self.view.frame = self.bounds
        self.view.layer.cornerRadius = self.bounds.size.width/2
        self.imgView.frame = self.view.bounds
        self.nameLab.frame = self.view.bounds
    }
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    @objc public func onPodium(_ podium:TalkfunApplyStatus)

    {
        self.podium = podium
        
        if (podium == .noApply) {
            self.nameLab.isHidden = true
            self.imgView.image = UIImage.init(named: "HTLive.bundle/ondium")
            self.imgView.isHidden = false
            self.view.backgroundColor = UIColor.clear
        }else if (podium == .applying || podium == .allowInvite) {
            self.nameLab.isHidden = false
            
            self.nameLab.text = "取消"
            self.view.backgroundColor = UIColor(red: 23/255.0, green: 145/255.0, blue: 51/255.0, alpha: 0.5)
            self.imgView.isHidden = true
        }else{
            
            self.imgView.image = UIImage.init(named: "HTLive.bundle/shangmai")
            self.imgView.isHidden = false
           
            self.view.backgroundColor = UIColor(red: 0/255.0, green: 0/255.0, blue: 0/255.0, alpha: 0.5)
            self.nameLab.isHidden = false
            self.nameLab.text = "xiamai"
        }

    }
    //切换语言
    @objc public func upDataLanguage(_ isOpenEng:Bool)

    {
        if (self.podium == .noApply ) {
            self.nameLab.isHidden = true
        } else if (self.podium == .applying || self.podium == .allowInvite) {
            if (isOpenEng) {
                self.nameLab.font = UIFont.PingFang(size: 11)
            } else {
                self.nameLab.font = UIFont.PingFang(size: 12)
            }
            
            self.nameLab.text = "取消"
            
            self.nameLab.sizeToFit()
            self.nameLab.isHidden = false
        } else {
            
            self.nameLab.text = "下麦"
            
        }
       
    }
    

}
